package test;

import java.awt.Color;
import java.awt.Graphics;
import java.math.*;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class SpinningGalaxy extends JPanel {
	private int N = 240;
	private double angleChange = 137.5;
	private double maxRadius = 200;
	private double theta;
	
	private double radius = 0;
	
	public SpinningGalaxy()
	{
		setSize(400,400);
	}
	
	public void start() throws InterruptedException
	{
		while(true)
		{
			Graphics g = this.getGraphics();
			for (int i = 0; i < 200; i++) {
		        radius = i/20;
		        theta = angleChange * i;

		        double x = 200+ radius * Math.cos(theta);
		        double y = 200+ radius * Math.sin(theta);
		        Color back = new Color(252, 252, 205);
				g.setColor(back);
		        g.fillOval((int)x,(int)y, 10, 10);
		        Thread.sleep(20);
		        
		        System.out.println("radius = "+radius+", x="+x+", y = "+y+", theta = "+theta);
		    }
			
			angleChange += 0.01;
			repaint();
			
		}
	}
	
	@Override
	public void paint(Graphics g) {
		
		
		Color color = new Color(26, 26, 26);
		g.setColor(color);
		g.fillRect(0, 0, 400, 400);
		
		
		
		
	}
	
	public static void main(String[] args)
	{
		
		SpinningGalaxy bb = new SpinningGalaxy();
		JFrame jf = new JFrame();
		jf.setSize(400, 400);
		jf.add(bb);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);
		
		try {
			bb.start();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
